home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 11334 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.7 KB  |  101 lines

  1. Path: realtime.net!usenet
  2. From: rflores@bga.com (Roberto Flores)
  3. Newsgroups: comp.lang.c++
  4. Subject: Need Help Creating DLL with Return Arguments
  5. Date: 13 Mar 1996 23:13:57 GMT
  6. Organization: Real/Time Communications Internet customer posting
  7. Message-ID: <4i7krl$g9i@news2.realtime.net>
  8. NNTP-Posting-Host: jake-4m.aip.realtime.net
  9. Mime-Version: 1.0
  10. X-RTcode: 4568691f31b59675d94756bb
  11. X-Newsreader: WinVN 0.93.11
  12.  
  13. I am using MSVC++ 1.5 on Windows 3.1 to create a DLL that receives a DOS 
  14. environment variable, uses getenv( "<variable>" ) and returns the 
  15. value back.  When I try to use the DLL in a 'C++' program, it GPFs when
  16. it attempts to call the function in the DLL created. Is there somthing I 
  17. am doing wrong or not doing?  Please help.  I am using the following code 
  18. to create the DLL (following the DLL code, is the code used to try to
  19. use it):
  20.  
  21. #include <stdlib.h>
  22. #include <windows.h>
  23.        
  24. int FAR PASCAL LibMain(HINSTANCE hInstance,WORD wDataSeg,WORD wHeapSize,LPSTR lpszCmdLine)
  25. {
  26.    if (wHeapSize > 0)
  27.       UnlockData(0);
  28.    return 1;
  29. }
  30.        
  31. int FAR PASCAL GetEnvironmentVar( char *envar, char *rtn_value )
  32. {
  33.    rtn_value = getenv( envar );
  34.    return(0);
  35. }   
  36.  
  37. void FAR PASCAL WEP(int nParameter)
  38. {
  39.     return;
  40. }
  41. //End of DLL code
  42.  
  43. Special thanks to Pete Grant for helping with the following code.  The
  44. code is the C++ program attempting to use the GETENVAR.DLL, I have
  45. created.  Code follows:
  46.  
  47.    #include <stdio.h>
  48.    #include <windows.h>
  49.    
  50.    int main ()
  51.    {
  52.     void prtuser(char *text1);
  53.        
  54.        prtuser("USERID");             
  55.        return(0);
  56.    }
  57.    
  58.    void prtuser(text1)
  59.    char *text1;
  60.    {                   
  61.       extern int _export _far _pascal GetEnvironmentVar( char *str1, char *str2);
  62.       char *rtn_envar ="**********";
  63.       char *envar =    "**********";
  64.  
  65.       HINSTANCE hinstGetEnVar;    
  66.       typedef BOOL (FAR *mycallback) (LPCSTR, LPSTR);
  67.       mycallback lpfnGetEnvironmentVar;
  68.       
  69.       sprintf(envar, text1);
  70.       printf(">%s<: ", envar);
  71.       hinstGetEnVar = LoadLibrary("GETENVAR.DLL");
  72.       
  73.       if ( hinstGetEnVar > 32 ) {
  74.          lpfnGetEnvironmentVar = (mycallback)GetProcAddress(hinstGetEnVar,"GetEnvironmentVar" );
  75.            if (lpfnGetEnvironmentVar != NULL ) { 
  76.                if ( (*lpfnGetEnvironmentVar) (envar, rtn_envar) )
  77.                    printf("%s\n", rtn_envar );                              
  78.                else
  79.                     printf("Function Call Failed:\n");
  80.            }
  81.            else
  82.               printf("Find Function Failed\n"); 
  83.       }
  84.       else {
  85.          printf("LoadLibrary Failed\n");
  86.       }
  87.       FreeLibrary( hinstGetEnVar );
  88.    }
  89.  
  90.  
  91. Please reply with help to:
  92.  
  93.     rflores@bga.com    or     Robert.Flores@tpwd.state.tx.us
  94.  
  95. ...please, please, please, please.
  96.  
  97. Thanks A Bunch
  98.  
  99. Roberto Flores
  100.  
  101.